<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/7/24
 * Time: 10:49
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller;


use app\common\lib\Show;
use app\common\lib\Status;
use think\App;

class Upload extends AdminBase
{
    public function image(): \think\response\Json
    {
        try {
            $result = \app\common\business\Upload::upload();
        } catch (\Exception $e) {
            return Show::json_show(Status::Error, $e->getMessage());
        }
        return Show::json_show(Status::Success, "ok", [
            "url" => "/" . $result[0]
        ]);
    }

    /**
     * @return \think\response\Json
     */
    public function avatar(): \think\response\Json
    {
        //{"code": 0, "msg": "success", "data": "/demo/demo.jpg"}，
        try {
            $result = \app\common\business\Upload::upload();
        } catch (\Exception $e) {
            return json([
                "code" => 1,
                "msg" => $e->getMessage(),
                "data" => ""
            ]);
        }
        return json([
            "code" => 0,
            "msg" => "ok",
            "data" => '/' . $result[0]
        ]);
    }
}